package com.gkwave.ui;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TimePicker;

public class CabRequest extends Activity implements OnClickListener{
	
	private final int DATE_DIALOG = 0x00;
	private final int TIME_DIALOG = 0x01;
	
	private EditText mDate = null;
	private EditText mTime = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cab_request);
		
		mDate = (EditText) findViewById(R.id.cab_request_date);
		mTime = (EditText) findViewById(R.id.cab_request_time);
		mTime.setOnClickListener(this);
		mDate.setOnClickListener(this);
	}

	@Override
	public void onClick(View arg0) {
		int id = arg0.getId();
		switch(id){
		case R.id.cab_request_date:
			showDialog(DATE_DIALOG);
			break;
		case R.id.cab_request_time:
			showDialog(TIME_DIALOG);
			break;
		}
	}

	@Override
	protected Dialog onCreateDialog(int id, Bundle args) {
		final Calendar cal = Calendar.getInstance();
		switch(id){
		case DATE_DIALOG:
			int year = cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH);
			int day = cal.get(Calendar.DAY_OF_MONTH);
			return new DatePickerDialog(this, dateListener, year, month, day);
		case TIME_DIALOG:
			int hourOfDay = cal.get(Calendar.HOUR_OF_DAY);
			int minute = cal.get(Calendar.MINUTE);
			return new TimePickerDialog(this, timeListener, hourOfDay, minute, true);
		default:
			return super.onCreateDialog(id, args);
		}
	}
	
	private DatePickerDialog.OnDateSetListener dateListener = 
	    new DatePickerDialog.OnDateSetListener() {
	        //@Override
	        public void onDateSet(DatePicker view, int yr, int monthOfYear, int dayOfMonth) {
	            String date = String.valueOf(dayOfMonth)+":"+String.valueOf(monthOfYear)+":"+String.valueOf(yr);
	            mDate.setText(date);
	     }
	};
	
	private TimePickerDialog.OnTimeSetListener timeListener = 
		new TimePickerDialog.OnTimeSetListener(){

			@Override
			public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
	            String date = String.valueOf(hourOfDay)+":"+String.valueOf(minute);
	            mTime.setText(date);
			}
		
	};

}
